
#include <BButton>
#include <BSystem>
#include <BStyle>

#include "Board.h"

Board::Board(BWidget* parent) : BDialog(parent)
{
	initTitleButton();
}
Board::Board(const BString& title, BWidget* parent) : BDialog(title, parent)
{
	initTitleButton();
}
Board::~Board()
{

}

void Board::initTitleButton()
{
	if (BButton* closeButton = this->titleButton(Button_Close))
	{
		closeButton->setTips("close");
	}
	BButton* maxButton = this->insertTitleButton(0, Button_Maximize);
	maxButton->setCheckable(true);
	maxButton->setTips("Maximize");

	BButton* manualButton = this->insertTitleButton(0, Button_Help);
	manualButton->setIcon(BSystem::TypedIcon(Icon_Question));
	manualButton->setCheckable(true);
	manualButton->setTips("Operation Manual");

	connect(maxButton, Signal_Toggled, &Board::slotButtonToggled);
	connect(manualButton, Signal_Clicked, &Board::slotManualButtonClicked);
	connect(this, Signal_Styled, &Board::slotStyleChanged);
}

void Board::slotButtonToggled(BButton* button, const BValue& value)
{
	if (value == true)
	{
		button->setTips("Normalize");
	}
	else
	{
		button->setTips("Maximize");
	}
}
void Board::slotManualButtonClicked(BButton* button, const BValue& value)
{
	post("open-manual", this->name());
}
void Board::slotStyleChanged(BObject* object, const BValue& value)
{
	const BStyle* style = value;
	BButton* button = this->titleButton(Button_Help);
	if (BIcon* icon = style->icon("help"))
	{
		button->setIcon(icon);
	}
}

void Board::mousePressEvent(const BMouseEvent& mouseEvent)
{
	BDialog::mousePressEvent(mouseEvent);
	this->raise();
}
